import { request } from '@umijs/max';
import * as API from "@/services";
export async function queryGroups(params: API.GroupPageQueryParams): Promise<API.RespPageResult<API.Group>> {
    return request('/api/v1/group', {
        params,
    });
}

export async function queryGroupUsedAreas(): Promise<API.RespPageResult<API.Area>> {
    return request('/api/v1/group/used-area');
}

export async function queryGroupTree(params: API.GroupTreeQueryParams): Promise<API.RespListResult<API.Group_TreeNode>> {
    return request('/api/v1/group/tree', {
        params,
    });
}

export async function queryGroupFlat(params: API.PageQueryParams): Promise<API.RespPageResult<API.Group>> {
    return request(`/api/v1/group/base-list`);
}

export async function queryGroup(bizId: API.EntityId): Promise<API.RespResult<API.Group>> {
    return request(`/api/v1/group/${bizId}`);
}

export async function createGroup(entity: API.Group_Create): Promise<API.RespResult<any>> {
    return request(`/api/v1/group`, {
        method: 'POST',
        data: entity,
    });
}

export async function modifyGroup(entity: API.Group_Modify): Promise<API.RespResult<any>> {
    return request(`/api/v1/group/${entity.id}`, {
        method: 'PUT',
        data: entity,
    });
}

export async function patchGroup(entity: API.Group_Patch): Promise<API.RespResult<any>> {
    return request(`/api/v1/group/${entity.id}`, {
        method: 'PATCH',
        data: entity,
    });
}

export async function deleteGroup(bizId: API.EntityId): Promise<API.RespResult<any>> {
    return request(`/api/v1/group/${bizId}`, {
        method: 'DELETE',
    });
}

export async function deleteGroups(bizIds: API.EntityId[]): Promise<API.RespResult<any>> {
    return request(`/api/v1/group`, {
        method: 'DELETE',
        data: {
            ids: bizIds,
        },
    });
}
